package com.greendragon.service.frontend.impl; 

import java.util.List;

import com.greendragon.persistence.dao.ICategoryDao;
import com.greendragon.persistence.dao.ICommentDao;
import com.greendragon.persistence.dao.IProductDao;
import com.greendragon.persistence.domain.Product;
import com.greendragon.persistence.domain.ProductCategory;
import com.greendragon.persistence.domain.ProductComment;
import com.greendragon.persistence.enmu.FetchOrderType;
import com.greendragon.persistence.enmu.LockType;
import com.greendragon.persistence.enmu.VerifyType;
import com.greendragon.service.frontend.IProductFrontendService;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-9-9 上午07:31:43
 * 
 */
public class ProductFrontendService extends BaseFrontendService<Product> implements IProductFrontendService{
	private IProductDao productDao;
	private ICommentDao<ProductComment> commentDao;
	private ICategoryDao<ProductCategory> categoryDao;
	
	@Override
	public List<Product> getByCategory(Long cid, int page) {
		Product expProduct = new Product();
		expProduct.setCategory(categoryDao.get(cid));
		expProduct.setBlock(false);
		return this.getByCondition(expProduct, page);
	}

	@Override
	public long getCommentCount(Long pid) {
		return commentDao.getCountOfObj(pid, LockType.UNLOCK, VerifyType.VERIFY);
	}

	@Override
	public List<ProductComment> getComments(Long pid, int page) {
		return commentDao.getOfObj(pid, pageLength*page, pageLength, LockType.UNLOCK, VerifyType.VERIFY, FetchOrderType.CREATE_DESC);
	}

	@Override
	public long getCountByCategory(Long cid) {
		Product expProduct = new Product();
		expProduct.setCategory(categoryDao.get(cid));
		expProduct.setBlock(false);
		return this.getCountByCondition(expProduct);
	}
	
	public void setProductDao(IProductDao productDao) {
		this.productDao = productDao;
		setDao(this.productDao);
	}

	public void setCommentDao(ICommentDao<ProductComment> commentDao) {
		this.commentDao = commentDao;
	}

	public void setCategoryDao(ICategoryDao<ProductCategory> categoryDao) {
		this.categoryDao = categoryDao;
	}

}
 